const mongoose = require('mongoose');

const messageSchema = new mongoose.Schema({
  sender: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
    required: true
  },
  receiver: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
    required: true
  },
  content: {
    type: String,
    required: true
  },
  isRead: {
    type: Boolean,
    default: false
  },
  type: {
    type: String,
    enum: ['text', 'image', 'activity', 'challenge'],
    default: 'text'
  },
  metadata: {
    // 用于存储分享的活动或挑战信息
    resourceId: mongoose.Schema.Types.ObjectId,
    title: String,
    description: String,
    imageUrl: String
  }
}, { timestamps: true });

module.exports = mongoose.model('Message', messageSchema); 